// Entry point for the game
#pragma once
#include "DemoApp.h"
#include "SimpleMesh.h"
#include "Player.h"
#include "Chaser.h"
#include "ObstacleMap.h"
#include "NetworkHandler.h"
#include "ConfigReader.h"
#include "PredictionArea.h"
#include <map>

class GameEntry : public DemoApp
{
private:
	int PLAYER_ID; // used to determine who is who on the server
	int GRIDSIZE_X;
	int GRIDSIZE_Z;
	float CELLSIZE_X;
	float CELLSIZE_Y;
	float CELLSIZE_Z;

	const static int MIN_BLOCK_NUM = 3;
	const static int MAX_BLOCK_NUM = 25;
	int numberOfBlocks;

	void SendExitMessage();

public:
	GameEntry(HINSTANCE hInstance, char* gameName);
	~GameEntry(void);
	int updateGameState(long time);
	int renderFrame(int time);
	int initGame(void);

	void initCamera(void);
	void initLights();
	void initMapObjects(void);
	void initNetworking(void);

	void update(long time);
	void updateBounds(long time);

	void processKeys(void);
	void parseMessage(std::string msg);

	void movePlayer();
	const D3DXVECTOR3 ensureBounds(const D3DXVECTOR3 &pos);

	bool bConnected; // connection status
	NetworkHandler hNetwork;
	ConfigReader configReader;

	SimpleMesh* pMesh; // terrain of our game
	ObstacleMap obstacleMap;
	
	Player player; // actual player running this client
	Chaser chaser; // bot version of the player
	bool isPlayerBot; // if the player is an auto chaser, then do topdown and render like a player

	std::map<int, Player*> otherPlayers;
	std::map<int, Chaser*> chasers;
	PredictionArea drArea; // triangle in which the player can move in before sending a DR message

	// timing variables
	time_t lastTime;

	char * PING_SERVER;
};
